home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1320 / 1320.xpi / chrome / gmanager.jar / content / utils / sounds.js < prev    next >
Text File  |  2010-01-22  |  2KB  |  48 lines

  1. // Gmail Manager
  2. // By Todd Long <longfocus@gmail.com>
  3. // http://www.longfocus.com/firefox/gmanager/
  4.  
  5. var gmanager_Sounds = new function()
  6. {
  7.   this.__proto__ = new gmanager_BundlePrefix("gmanager-sounds-");
  8.   
  9.   this.WAV_FILTER_TYPE = "*.wav";
  10.   
  11.   this.init = function()
  12.   {
  13.     this._ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  14.     this._soundService = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
  15.     this._soundService.init();
  16.   }
  17.   
  18.   this.play = function(aPath)
  19.   {
  20.     var uri = null;
  21.     
  22.     try {
  23.       var localFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  24.       localFile.initWithPath(aPath);
  25.       
  26.       if (localFile.exists())
  27.         uri = this._ioService.newFileURI(localFile);
  28.     } catch(e) {
  29.       uri = this._ioService.newURI(aPath, null, null);
  30.     }
  31.     
  32.     if (uri)
  33.       this._soundService.play(uri);
  34.   }
  35.   
  36.   this.selectFile = function()
  37.   {
  38.     var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
  39.     
  40.     filePicker.init(window, this.getString("select-file"), Components.interfaces.nsIFilePicker.modeOpen);
  41.     filePicker.appendFilter(this.getFString("sound-files", [this.WAV_FILTER_TYPE]), this.WAV_FILTER_TYPE);
  42.     filePicker.show();
  43.     
  44.     return (filePicker.file ? filePicker.file.path : null);
  45.   }
  46.   
  47.   this.init();
  48. }